//q5.cpp
//This program set grades to an array and print it together with the logical and physical size
//
//Binyamin 18 Jan 2018
//---------------------------------------------------------------------------------------------

#include<iostream>

using namespace std;

//grades_array
//input: integers, stream end with -1
//output: an array with the grades and the logical and physical size of the array.
//complex: O(n^2) - the function runs for the number of inputs and the transfer rate, thus n^2.
int *grades_array(int *size, int *physize)
{
	int current; // current input
	int j; //looper
	int *temp; // temporary array
	int *ret; // the array to return
	*size = 0;
	*physize = 2;
	ret = new int[*physize];
	cin >> current;
	while(current != -1)
	{
		if(*size > *physize)
		{
			(*physize) *=2;
			temp = new int(*physize);
			for(j=0;j<*size;j++)
				temp[j] = ret[j];
			delete[]ret;
			ret = temp;
		}
		ret[*size] = current;
		(*size)++;
		cin >> current;


	}
	return ret;

}

//1. prompt the user for the grades
//2. print the returned array
//3. print the logical and physical size
int main()
{
	int i; //looper
	int *grades; // the array
	int size, physize; // logical and physical size for the array
	cout << "Please enter grades" << endl;
	grades = grades_array(&size, &physize);
	cout << "The grades are" << endl;
	for(i=0;i<size;i++)
	       cout << grades[i] << '\t';
	cout << endl << size << '\t' << physize << endl;	
}
//output
//Please enter grades
//80 90 70 76 78 86 -1
//The grades are
//80	90	70	76	78	86	
//6	8
